    const App = getApp();

    const func = require('../../../utils/func');

    Page({
        data: {
            userInfo:{}, //用户信息
            // sex: '男',
            sexList: [
                {sex: '男', value:'1'},
                {sex: '女', value:'2'},
                {sex: '保密', value:'0'}
            ],
            date:'请选择'
        },
        onLoad(options) {
            let _this = this;
            _this.getUserDetail();
        },
        // 获取当前用户信息
        getUserDetail() {
            let _this = this;
            App._requestApi(_this, App.globalData.config.apiUsersdetailUrl,{}, function(res) {
                if (!res.data.userInfo) {
                    res.data.isLogin = false;
                    // 移除token users_id
                    wx.removeStorageSync('token');
                    wx.removeStorageSync('users_id');
                }
                _this.setData({
                    userInfo: res.data.userInfo
                })
            })
        },
        // 下拉刷新
        onPullDownRefresh() {
            this.getUserDetail();
            wx.stopPullDownRefresh()
        },
        // 触底加载
        onReachBottom() {

        },
        changeAvatar(){
            let _this = this;
            wx.chooseImage({
            count: 1,
            sizeType: ['original', 'compressed'],  //默认原图还是压缩图
            sourceType: ['album', 'camera'],       //默认指定来源是相机还是相册
            name:'file',
            success: function(res) {
                wx.uploadFile({
                  filePath: res.tempFilePaths[0],
                  name: 'file',
                  url: App.globalData.config.shopUploadsUrl,
                  success:function(res) {
                      let result = typeof res.data === 'object' ? res.data : JSON.parse(res.data);
                      if  (result.code === 1) {
                          _this.setData({
                              'userInfo.head_pic' : App.globalData.config.domain+result.data.img_url
                          })
                      }
                  }
                })
                // this.setData({
                //     img : res.tempFilePaths[0]
                // })
            }
            });
        },
            
        // 性别选择
        sellerUsersSex(e) {
            let _this = this;
            let index = e.detail.value;
            _this.setData({
                'userInfo.sex': _this.data.sexList[index].sex,
                'userInfo.sexvalue': _this.data.sexList[index].value,
            } );
        },

        changeDate(e){
            this.setData({
                'userInfo.birthday':e.detail.value
            })
        },
        saveData(e) {
            let _this = this,
            values = e.detail.value;
            let userInfo = _this.data.userInfo;
            App._requestPost(_this, App.globalData.config.userSaveUserInfoUrl, {
                head_pic:userInfo.head_pic,
                mobile:userInfo.mobile,
                birthday:values.birthday,
                intro:values.intro,
                sex:userInfo.sexvalue
            }, result => {
                App.showSuccess('修改成功!', function() {
                    wx.switchTab({
                      url: '/pages/user/index',
                    })
                })
            })
        },
        // 跳转到其他界面
        jumpToUrl(e) {
            func.jumpToUrl(e)
        }
})